package com.meida.boot.handler;

import com.meida.common.mybatis.entity.EntityMap;
import com.meida.common.mybatis.interceptor.GetInterceptor;
import com.meida.common.mybatis.query.CriteriaQuery;
import com.meida.common.utils.FlymeUtils;
import com.meida.module.product.client.entity.ProdShop;
import com.meida.module.product.provider.service.ProdShopService;
import com.meida.module.system.client.entity.SysCompany;
import com.meida.common.enums.ColleconEnum;
import com.meida.module.system.provider.service.SysColleconService;
import com.meida.module.system.provider.service.SysCompanyService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 商家店铺详情
 */
@Component("shopGetHandler")
@Log4j2
public class ShopGetHandler implements GetInterceptor {

    @Autowired
    private ProdShopService shopService;

    @Autowired
    private SysColleconService colleconService;

    @Autowired
    private SysCompanyService companyService;

    /**
     * 查询条件扩展
     *
     * @param cq
     * @return
     */
    @Override
    public void prepare(CriteriaQuery cq, EntityMap params) {
    }


    /**
     * 返回结果集扩展
     *
     * @param cq
     * @return
     */
    @Override
    public void complete(CriteriaQuery cq, EntityMap map) {
        Long shopId = map.getLong("shopId");


        //店铺收藏标记
        Integer scTag = colleconService.countCollecon(shopId, ColleconEnum.SC, ProdShop.class);
        //店铺收藏总数
        Integer shopScCount = colleconService.countAllCollecon(shopId, ColleconEnum.SC, ProdShop.class);
        map.put("shopScCount", shopScCount);
        map.put("scTag", scTag);

        SysCompany company = companyService.getById(shopId);
        String companyTel = "";
        String companyName = "";
        if (FlymeUtils.isNotEmpty(company)) {
            companyTel = company.getLinkTel();
            companyName = company.getCompanyName();
        }
        map.put("companyTel", companyTel);
        map.put("companyName", companyName);
        map.put("managerId", company.getManagerId());


    }
}
